#include "StdAfx.h"
#include "VDP.h"

CVDP::CVDP()
{
}

CVDP::~CVDP()
{
}

void CVDP::Reset()
{
}

u8 CVDP::Read(u8 port)
{
	return(0);
}

void CVDP::Write(u8 port,u8 data)
{
	port &= 0xC1;
	if(port == 0x80) {	//data
		if(ctrlwritenum == 0) {
			ctrlwritenum = 1;
		}
		else {
			ctrlwritenum = 0;
		}
	}
	if(port == 0x81) {	//control
		if(ctrlwritenum == 0) {
			addrlatch = data;
			ctrlwritenum = 1;
		}
		else {
			switch(data & 0xC0) {
				case 0x00: //read vram
					addrreg = addrlatch | ((data & 0x3F) << 8);
					break;
				case 0x40: //write vram
					addrreg = addrlatch | ((data & 0x3F) << 8);
					break;
				case 0x80: //write vdp reg
					regs[data & 0xF] = addrlatch;
					break;
				case 0xC0: //write cram
					addrreg = addrlatch & 0x1F;
					break;
			}
			ctrlwritenum = 0;
		}
	}
}
